// 参赛团队
const { Model, DataTypes } = require('sequelize');

const sequelize = require('./database');
const User = require('./user');
const Match = require('./match');

class TeamGroup extends Model {}

TeamGroup.init({
  teamName: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"队伍名称",
    unique:true
  },
  teamAbbreviation: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"队伍简称"
  },
  englishName: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"英文名称"
  },
  nation: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"国家或地区"
  },
  province: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"省级"
  },
  city: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"市级"
  },
  address: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"详细地址"
  },
  teamLeader: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"团队负责人"
  },
  phone: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"手机号码"
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"email"
  },
  slogan: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"团队口号"
  },
  image: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"团队图片"
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: User, // 指定关联的模型
      key: 'id'
    }
  },
  matchId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: Match, // 指定关联的模型
      key: 'id'
    }
  }

}, {
  sequelize,
  modelName: 'teamgroup'
});
TeamGroup.belongsTo(Match,{ foreignKey: 'matchId' })
TeamGroup.belongsTo(User,{ foreignKey: 'userId' })

module.exports = TeamGroup;